﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="QuotationList.aspx.cs" Inherits="PMS.UI.CM.QuotationList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var rowData;
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/CM/QuotationAjax.aspx?method=GetQuotationList',
                loadMsg: '数据加载中请稍后……',
                pagination: true,
                rownumbers: true,
                idField: "ID",
                lines: true,
                // fitColumns:true,
                frozenColumns: [[{
                    field: 'ck', checkbox: true, width: 30
                }, {
                    field: 'ID', title: 'ID', width: 60, align: "center"
                }, {
                    field: 'Code', title: '报价单编号', sortable: false, width: 120, align: "center"
                }, {
                    field: 'State', title: '状态', width: 80, align: "center", formatter: function (value, row, index) {
                        return com.getArrayText(StaticCombo.QuotState, value)
                    }
                }]],
                columns: [[
                    {
                        field: 'CustomerID', title: '客户名称', align: "center", width: 200,
                        formatter: function (value, row, index) {
                            return row.ComName
                        }
                    }, {
                        field: 'Date', title: '报价日期', sortable: false, width: 120, align: "center"
                    },
                    {
                        field: 'SellerCompany', title: '收款单位', sortable: false, width: 200, align: "center"
                    }, {
                        field: 'SellerBank', title: '收款开户行', sortable: false, width: 200, align: "center"
                    }, {
                        field: 'SellerAccount', title: '收款账号', sortable: false, width: 200, align: "center"
                    },
                    {
                        field: 'Note', title: '备注', sortable: false, width: 200, align: "center"
                    }
                ]],
                //singleSelect: true,
                pageSize: 20,
                queryParams: com.serializeSearchArray("form1"),
                pageList: [20, 50, 100],
                striped: true
            });
        })

    </script>
    <script>

        function funcSearch() {
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
        }

        function funcAdd() {
            top.wrapper.addTab("产品细则", "/UI/CM/QuotationDetail.aspx?action=add");

        }

        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                top.wrapper.addTab("产品细则", "/UI/CM/QuotationDetail.aspx?Id=" + row.ID + "&State=" + row.State + "&action=edit");
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该条记录吗？', function (r) {
                if (r) {
                    var rowData = $("#tbList").datagrid("getSelected");
                    if (rowData) {
                        if (rowData.State == "0") {
                            com.ajax({
                                url: '/Logic/CM/QuotationAjax.aspx?method=DelQuotation',
                                data: { Id: rowData.ID },
                                success: function (data) {
                                    com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $("#tbList").datagrid('clearSelections'); })
                                }
                            })
                        } else {
                            com.message('information', '报价单当前状态无法删除')
                        }
                    }
                }
            });
        }

        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        function funcReload() {
            $("#form1").form("reset");
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            funcCancel()
        }

        //生成合同
        function funcGenContra() {
            $.messager.confirm('确认对话框', '您确定要生成合同吗？', function (r) {
                if (r) {
                    var rows = $("#tbList").datagrid("getSelections");
                    if (rows.length == 0) {
                        com.message("information", "请选中一行");
                        return
                    }
                    var url = "/UI/CM/ContractDetail.aspx?action=add";
                    for (var i = 0; i < rows.length; i++) {
                        if (rows[0].CustomerID != rows[i].CustomerID) {
                            com.message("error", "存在不一样的客户，请重新选择");
                            return;
                        }
                        //已合同或已合同已订单的状态下不能再次生成合同
                        if (rows[i].State == '1' || rows[i].State == '3') {
                            com.message("error", "报价单" + rows[i].Code + "当前的状态不能生成合同，请重新选择");
                            return;
                        }
                        url += "&ID=" + rows[i].ID;
                    }
                    top.wrapper.addTab("添加合同信息", url);
                }
            });
        }

        //生成订单
        function funcGenProd() {
            var rows = $("#tbList").datagrid("getSelections");
            if (rows.length > 1) {
                com.message("error", "不能选中多行生成订单，请重新选择");
                return
            }

            var row = $("#tbList").datagrid("getSelected");
            if (row) {
                //已订单或已合同已订单的状态下不能再次生成订单
                if (row.State == '2' || row.State == '3') {
                    com.message("error", "报价单" + row.Code + "当前的状态不能生成订单，请重新选择");
                    return;
                }
                $.messager.confirm('确认对话框', '您确定要生成订单吗？', function (r) {
                    if (r) {
                        com.ajax({
                            url: '/Logic/CM/QuotationAjax.aspx?method=JoinTechParam',
                            data: { QuotationID: row.ID, unit: 0 },
                            success: function (data) {
                                if (data.state == "success") {
                                    top.wrapper.addTab("生产订单细则", "/UI/PM/ProductOrderDetail.aspx?action=add&quotID=" + row.ID)
                                }
                                else {
                                    com.message("error", "产品技术参数生成失败，请检查各产品的组分浓度是否录入完整！");
                                }
                            }
                        })
                    }
                });
            } else {
                com.message("information", "请选中一行");
            }
        }

        //打印报价单
        function funcPrintQuot() {

            var rows = $("#tbList").datagrid("getSelections");
            if (rows.length > 1) {
                com.message("error", "不能选中多行打印，请重新选择");
                return
            }
            
            var row = $("#tbList").datagrid("getSelected");
            if (row) {
                com.ajax({
                    url: '/Logic/CM/QuotationAjax.aspx?method=JoinTechParam',
                    data: { QuotationID: row.ID, unit: 0 },
                    success: function (data) {
                        if (data.state == "success") {
                            top.wrapper.addTab("打印报价单", "/UI/CM/PrintQuotation.aspx?Id=" + row.ID);
                        }
                        else {
                            com.message("error", "产品技术参数生成失败，请检查各产品的组分浓度是否录入完整！");
                        }
                    }
                });
            } else {
                com.message("information", "请选中一行");
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="divTotal" style="height: 100%; width: 100%">
        <div id="master" class="container_12" style="height: auto">
            <form id="form1">
                <div class="grid_1 sealbl" style="text-align: right;">
                    报价单号:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="Code" name="Code" data-cp="co" />
                </div>
                <div class="grid_1 sealbl" style="text-align: right;">
                    客户名称:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input id="ComName" name="ComName" data-cp="co" />
                </div>
                <div class="grid_1 sealbl" style="text-align: right;">
                    报价单状态 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" class="easyui-combobox" id="State" name="State" data-cp="=" data-options="valueField:'value',textField:'text',data:StaticCombo.QuotStateQuery,value:'',panelHeight:'auto'" />
                </div>
            </form>
        </div>
        <table id="tbList" title="报价单信息表" style="width: 100%">
        </table>
    </div>
</asp:Content>
